<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <p>电脑价格：{{price|addPriceIcon}}</p>
      <input type="text" v-model="content" @change="changeEvent" />
      <h3>{{viewConten|changeCapitalLetter}}</h3>
      <h3>{{viewConten|addNamePrefix}}</h3>
    </div>
    <script src="../lib/vue.js"></script>
    <script>
      Vue.filter('addNamePrefix', (value) => {
        return 'my name is' + value
      })
      let vm = new Vue({
        el: '#app',
        data: {
          price: 200,
          viewConten: '铝型材',
          content: '',
        },
        methods: {
          changeEvent() {
            this.viewConten = this.content
          },
        },
        filters: {
          addPriceIcon(value) {
            console.log(value)
            return '￥' + value
          },
          changeCapitalLetter(value) {
            if (value) {
              let str = value.toString()
              let newArr = str.split(' ').map((ele) => {
                return ele.charAt(0).toUpperCase() + ele.slice(1)
              })
              return newArr.join(' ')
            }
          },
        },
      })
    </script>
  </body>
</html>
